﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Security.Cryptography;
using System.Text;

namespace ESAM_Assignment_3
{
    public static class UserLogin // was created to hash the input & verify the hashes
    {
        public static string Hash(string password) //a method to hash the inputs
        {
            SHA1 sha1 = SHA1.Create(); // to create a new object
            StringBuilder sb = new StringBuilder(); // to modify a string
            byte[] hashpw = Encoding.Default.GetBytes(password);// convert the string into array of bytes

            hashpw = sha1.ComputeHash(hashpw);//compute the input into hash value

            foreach (byte b in hashpw)
            {
                sb.Append(b.ToString("x2"));//helps to convert into hexadecimal
            }

            password = sb.ToString();

            return password;
        }

        public static bool VerifyLogin(string enteredPW, string databasePW)
        {
            enteredPW = Hash(enteredPW);//compute into hash value
            return (enteredPW == databasePW);//hash value will be compared. if true it will return true
        }
    }
}